using System;
using System.Collections;
using UnityEngine;
using QFramework;
using Random = UnityEngine.Random;

namespace Survivor
{
	public partial class SimpleAxe : ViewController
	{
		private float _currentSeconds= 0;
		public Vector2 axeInitSpeedXRange;  // 初速度X范围
		public Vector2 axeInitSpeedYRange;  // 初速度Y范围
		public float gravity;
		void Start()
		{
			// Code Here
		}

		private void Update()
		{
			_currentSeconds += Time.deltaTime;
			if (_currentSeconds >= Global.SimpleAxeInterval.Value)
			{
				_currentSeconds = 0;
				StartCoroutine(IGenerateAxe());
			}
		}
		
		IEnumerator IGenerateAxe()
		{
			for (int i = 0; i < Global.SimpleAxeCount.Value + Global.FlyThingCount.Value; i++)
			{
				
				Axe.Instantiate().Self((self) =>
				{
					var axeCpt = self.GetComponent<Axe>();
					if (axeCpt)
					{
						Vector2 initSpeed = new Vector2(Random.Range(axeInitSpeedXRange.x, axeInitSpeedXRange.y),
							Random.Range(axeInitSpeedYRange.x, axeInitSpeedYRange.y));
						axeCpt.Init(transform.position, initSpeed, gravity);
					}
				}).LocalScale(Vector3.one * Global.SimpleAxeScale.Value).Show();
				yield return new WaitForSeconds(0.1f);
			}
		}
	}
}
